package router

import (
	"net/http"
	"walnut/internal/handler/base"
	"walnut/internal/middleware"
	"walnut/kernel"
)

func Base(mux *http.ServeMux) {
	g1 := kernel.MiddlewareFuncGroup(middleware.Log)
	g2 := kernel.MiddlewareFuncGroup(middleware.Auth, g1)
	// 注册
	mux.HandleFunc("/register", g1(base.Register))
	// 登录
	mux.HandleFunc("/login", g1(base.Login))
	// 登录信息
	mux.HandleFunc("/login/info", g2(base.Info))

	// 上传业务功能
	// 静态文件访问路由
	mux.Handle("/uploads/", http.StripPrefix("/uploads/", http.FileServer(http.Dir("uploads"))))
	// 文件上传路由
	mux.HandleFunc("/upload/file", g2(base.UploadFile))

	// 菜单管理接口
	mux.HandleFunc("/menu/create", g2(base.CreateMenu))
	mux.HandleFunc("/menu/list", g2(base.GetMenus))
	mux.HandleFunc("/menu/update", g2(base.UpdateMenu))
	mux.HandleFunc("/menu/delete", g2(base.DeleteMenu))
}
